package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import com.example.fw.GroupObject;
import com.example.fw.Groups;

public class GroupCreationTests extends TestBase {

	@Test(dataProvider = "groupsFromFile", dataProviderClass = GroupDataGenerator.class)
	public void testValidGroupCanBeCreated(GroupObject validGroup) throws Exception {
		Groups oldList = app.getGroupHelper().getGroups();
		app.getGroupHelper().createGroup(validGroup);
		Groups newList = app.getGroupHelper().getGroups();
		assertThat(newList, equalTo(oldList.withAdded(validGroup)));
	} 

	@AfterClass
	public void testUiAndDbConformsWithModel(){
		if (app.getProperty("ui.check") != null) {
			Groups modelList = app.getHibernateHelper().getGroups();
			Groups DbList = app.getHibernateHelper().getGroups();
			Groups UiList = app.getGroupHelper().getUIGroups();
			assertThat(DbList, equalTo(UiList));
			assertThat(DbList, equalTo(modelList));		
		}
	}

	@Test
	public void testGroupWithEmptyDataCanBeCreated() throws Exception {	
		GroupObject emptyDataGroup = new GroupObject().setName("").setHeader("").setFooter("");
		Groups oldList = app.getGroupHelper().getGroups();
		app.getGroupHelper().createGroup(emptyDataGroup);
		Groups newList = app.getGroupHelper().getGroups();
		assertThat(newList, equalTo(oldList.withAdded(emptyDataGroup)));
	}
}